import mock from "mockjs";

const data = [
  {
    username: "123",
    password: "123",
    token: 1,
  },
  {
    username: "1807",
    password: "123",
  },
];
mock.mock("/api/login", "post", (req) => {
  const { username, password } = JSON.parse(req.body);

  if (username && password) {
    let newList = data.filter((item) => {
      return (
        item.username * 1 === username * 1 && item.password * 1 === password * 1
      );
    });
    return {
      code: 200,
      message: "登陆成功",
      data: newList,
    };
  } else {
    return {
      code: 2001,
      message: "登陆失败",
    };
  }
});
